package jee.boot.module.quartz.task;

import jee.boot.common.utils.DateUtils;
import jee.boot.common.utils.SpringContextHolder;
import jee.boot.module.quartz.entity.Quartz;
import jee.boot.module.quartz.service.QuartzService;
import org.quartz.*;

import java.util.Date;

/**
 * 同步任务接口实现,需要增加两个注解
 * @PersistJobDataAfterExecution
 * @DisallowConcurrentExecution
 */
@PersistJobDataAfterExecution
@DisallowConcurrentExecution
public class TaskSynchDemo  implements Job {

    private QuartzService service=SpringContextHolder.getBean(QuartzService.class);

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        JobDataMap dataMap = context.getMergedJobDataMap();
        long time=System.currentTimeMillis();
        System.out.println("(同步)开始:"+ DateUtils.formatDate(new Date(time),"yyyy-MM-dd HH:mm:ss"));
        try {
            service.get(new Quartz());
            Thread.sleep(1000*10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("(同步)结束:"+DateUtils.formatDate(new Date(time),"yyyy-MM-dd HH:mm:ss"));
    }
}
